home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cqa.zip / 3PBGIAD.TC next >
Text File  |  1991-04-01  |  2KB  |  83 lines

  1. QUESTION:  How do I link a third party BGI driver into my program?
  2.  
  3. ANSWER:    The following procedure and example should help you out.
  4.  
  5.    (1) convert vga256.BGI to an object file with this command:
  6.  
  7.           BGIOBJ vga256.BGI vga256.obj _vga256_driver
  8.  
  9.    (2) Create a project file for the program that links in the driver.
  10.        The project should contain two items:  1) test.c 2) vga256.obj
  11.  
  12.    (3) Here's what test.c would look like:
  13.  
  14. /*-------------------------- 3PBGIAD.C --------------------------*/
  15. #include <graphics.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <conio.h>
  19.  
  20. /* function prototypes */
  21. int huge alwayszero(void);
  22. void checkerrors(void);
  23. void  _Cdecl vga256_driver(void);  /* DON'T FORGET THE PROTOTYPE! */
  24.  
  25. int main(void)
  26. {
  27.    int gdriver, gmode;
  28.  
  29.    /* install the user defined driver into the system */
  30.    gdriver = installuserdriver("vga256", alwayszero);
  31.  
  32.    /* check for any installation errors */
  33.    checkerrors();
  34.  
  35.    /* register the driver with the graphics system */
  36.    registerbgidriver(vga256_driver);
  37.  
  38.    /* check for any installation errors */
  39.    checkerrors();
  40.  
  41.    /* initialize graphics and local variables */
  42.    initgraph(&gdriver, &gmode, "");
  43.  
  44.    /* check for any initialization errors */
  45.    checkerrors();
  46.  
  47.    /* draw a line */
  48.    setcolor(WHITE);
  49.    line(0, 0, getmaxx(), getmaxy());
  50.  
  51.    /* clean up */
  52.    getch();
  53.    closegraph();
  54.    return 0;
  55. } /* end of main() */
  56.  
  57. /*-------------------------------------------------------------------
  58.   alwayszero -
  59. */
  60.  
  61. int huge alwayszero(void)
  62. {
  63.    return 0;
  64. } /* end of alwayszero() */
  65.  
  66. /*-------------------------------------------------------------------
  67.   checkerrors - check for and report any graphics errors
  68. */
  69.  
  70. void checkerrors(void)
  71. {
  72.    int errorcode;
  73.  
  74.    /* read result of last graphics operation */
  75.    errorcode = graphresult();
  76.    if (errorcode != grOk) {
  77.       printf("Graphics error: %s\n", grapherrormsg(errorcode));
  78.       printf("Press any key to halt:");
  79.       getch();
  80.       exit(1);
  81.    }
  82. } /* end of checkerrors() */
  83.